package cn.itcast.bos.mq;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;

import cn.itcast.bos.utils.SmsUtils;

/**
 * 
 * @author Administrator
 * 创建消费者
 */
@Service("smsConsumer")
public class SmsConsumer implements MessageListener {
    
	//接收消息
	@Override
	public void onMessage(Message message) {
     //将消息强转成map类型
	MapMessage mapMessage=(MapMessage) message;
	
	//调用阿里大于发送短信
	SendSmsResponse response;
	try {
		response = SmsUtils.sendSms(mapMessage.getString("telephone"),
				mapMessage.getString("randomCode"));
	
	
		if (response.getCode() != null && response.getCode().equals("ok")) {
			  System.out.println("短信发送成功");
			 
			 } else {
			  
			 System.out.println("短信发送失败"); }
	
	} catch (Exception e) {
		
		e.printStackTrace();
	}

			
			
			 
	
	
	}

}
